<template>
  <div class="ChildPage TablePage">
    <vb-table :option="option" ref="table"
               @row-del="rowDel"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @on-load="getList">
    </vb-table>
    <ChildDictionary ref="childDictionary" :parentDicData="dicData"></ChildDictionary>
  </div>
</template>

<script>
import ChildDictionary from "./childDictionary.vue"
  export default {
    mixins: [],
    components: {
      ChildDictionary
    },
    data() {
      let self = this
      return {
        option: {
          selection: true,
          index: true,
          menuWidth: 200,
          column: [
            {
              label: "字典名称",
              prop: 'name',
              form: {
                rules: [
                  {
                    required: true,
                    trigger: "click"
                  }
                ],
              },
            },
            {
              label: "字典编号",
              prop: "key",
              search: {
                show: true,
                label: "关键词",
                prop: "keyword",
                hiddenLabel: true,
                placeholder: "\ue605 名称/编号/备注"
              },
              form: {
                rules: [
                  {
                    required: true,
                    trigger: "click"
                  }
                ],
              },
            },
            {
              prop: "type",
              formShow: false,
              tableShow: false,
              defaultSearch: true,
              defaultForm: true,
              form: {
                default: this.$route.query.type || 1
              },
            },
            {
              label: "字典排序",
              prop: "sort",
              type: "inputNumber",
              width: 80,
              align: "center",
              form: {
                default: 1,
                rules: [
                  {
                    required: true,
                    trigger: "click"
                  }
                ],
              },
            },
            {
              label: "有效",
              prop: 'effect',
              type: "switch",
              align: "center",
              width: 80,
              form: {
                default: true
              }
            },
            {
              label: "字典备注",
              prop: 'remark',
              type: "textarea",
              form: {
                span: 24,
              }
            }
          ],
          form: {
            width: 600
          },
          handleBtnList: [
            {
              key: "edit",
            },
            {
              key: "delete",
            },
            {
              label: "编辑子项",
              icon: "el-icon-circle-plus-outline",
              type: "text",
              callback: function (row) {
                self.addChild(row)
              }
            },
          ],
        },
        dicData: []
      }
    },
    computed: {},
    mounted() {
    },
    methods: {

      /**
       * 查询数据列表信息
       * @param page
       * @param size
       * @param search 检索条件
       * @param done
       */
      getList (page, size, search, done) {
        let self = this
        this.$api.getParentDictionaryList(Object.assign({
          pageIndex: page,
          pageSize: size
        }, search)).then(res => {
          self.dicData = res.data
          done(res)
        })
      },

      /**
       * 新增数据处理
       * @param form
       * @param done
       */
      rowSave (form, done) {
        this.$api.addParentDictionary(form).then((res) => {
          done(res)
        })
      },

      /**
       * 更新数据处理
       * @param form
       * @param done
       */
      rowUpdate (form, done) {
        this.$api.updateParentDictionary(form).then((res) => {
          done(res)
        })
      },

      /**
       * 删除数据处理
       * @param ids
       * @param done
       */
      rowDel (ids, done) {
        this.$api.deleteParentDictionary({
          ids: ids
        }).then((res) => {
          done(res)
        })
      },

      /**
       * 添加子项
       * @param row
       */
      addChild (row) {
        this.$refs.childDictionary.open(row)
      }
    },
    watch: {
      "$route.fullPath": function () {
        this.reload()
      }
    }
  }
</script>

<style lang="scss" scoped>
</style>
